package com.liner;

import java.util.Arrays;

public class MaxOfArrayDemo {
    public static void main(String[] args) {
        int[] arr = new int[12];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
            System.out.print(arr[i] + "\t");
        }
        System.out.println("\n************");


        //最大值\最小值算法
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {

            if (arr[i] > max) {
                max = arr[i];
            }
        }
        System.out.println("最大值为:" + max);


        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {

            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println("最小值为:" + min);


        System.out.println("\n************");

        System.out.println("冒泡 ---- 从大到小");

        //冒泡排序
        for (int i = 0; i < arr.length -1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j]<arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        //遍历排序后数组
        for (int j : arr) {
            System.out.print(j + "\t");
        }


        System.out.println("\n************");

        System.out.println("排序 ---- 从小到大");
        //排序
        Arrays.sort(arr);

        //遍历排序后数组
        for (int j : arr) {
            System.out.print(j + "\t");
        }
        System.out.println("\n************");

    }
}
